﻿using System.Collections.Generic;
using System.Web.Mvc;
using TwitterBootstrapMVC;
using Web.UI.AdminLTE.Common;
using Web.UI.AdminLTE.Enums;
using Web.UI.TypeExtensions;

namespace Web.UI.AdminLTE.Controls.Widget
{
    public class SmallBox : HtmlElementBase
    {
        private Icon _icon;
        private string _href;
        private string _description;
        private string _linkText;
        private string _title;
        private BootstrapColor _backgroundColor;
        public SmallBox(BootstrapColor color)
        {
            _backgroundColor = color;
            EnsureClass("small-box");
        }

        public override string ToHtmlString()
        {
            return TagBuilderExtensions.New("div")
                     .MergeHtmlAttributes(HtmlAttr.FormatHtmlAttributes())
                     .AddOrMergeCssClass("bg-" + _backgroundColor.GetEnumDescription())
                     .AppendHtml(TagBuilderExtensions.New("div")
                         .AddOrMergeCssClass("inner")
                         .AppendHtml(string.Format("<h3>{0}</h3>", _title))
                         .AppendHtml(string.Format("<p>{0}</p>", _description)))
                         .AppendHtml(TagBuilderExtensions.New("div")
                            .AddOrMergeCssClass("icon").Html(_icon))
                     .AppendHtml(TagBuilderExtensions.New("a")
                         .AddOrMergeCssClass("small-box-footer")
                         .AddOrMergeAttribute("href", _href)
                         .AppendHtml(_linkText + "&nbsp;")
                         .AppendHtml(new Icon("fa fa-arrow-circle-right")))
                     .ToString(TagRenderMode.Normal);
        }

        public SmallBox Title(string title)
        {
            _title = title;
            return this;
        }

        public SmallBox BackgroundColor(BootstrapColor color)
        {
            _backgroundColor = color;
            return this;
        }

        public SmallBox Description(string description)
        {
            _description = description;
            return this;
        }

        public SmallBox Icon(Icon icon)
        {
            _icon = icon;
            return this;
        }

        public SmallBox Icon(string icon)
        {
            return Icon(new Icon(icon));
        }

        public SmallBox Link(string linkText, string href)
        {
            _linkText = linkText;
            _href = href;
            return this;
        }

        //  Common methods for all html elements
        #region Common Methods

        public SmallBox HtmlAttributes(IDictionary<string, object> htmlAttributes)
        {
            MergeHtmlAttributes(htmlAttributes);
            return this;
        }

        public SmallBox HtmlAttributes(object htmlAttributes)
        {
            MergeHtmlAttributes(htmlAttributes);
            return this;
        }

        public SmallBox Id(string id)
        {
            SetId(id);
            return this;
        }

        public SmallBox Class(string cssClass)
        {
            EnsureClass(cssClass);
            return this;
        }

        public SmallBox Data(object htmlDataAttributes)
        {
            MergeHtmlDataAttributes(htmlDataAttributes);
            return this;
        }

        #endregion
    }
}